<?php
/*------------------------------------------------------------------------------
this file is part of Web Application Kit http://webappkit.net
Copyright (C) 2006 J.Ducastel <jducastel@jducastel.fr>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
------------------------------------------------------------------------------*/

/**
* very basic robot filtering by asking questions which an human is supposed to answer
* stores questions withina yaml file
* @author J.Ducastel <jducastel@jducastel.fr>
* @version 
*/
class turingQuestions extends wakService {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access public
	*/
	function turingQuestions() {
		$this->__construct();
	}/**/
	
	/**
	* "real" constructor
	* @access
	*/
	function __construct() {
		parent::__construct();
		// loading data
		$lib=&wak::getservice('waklib');
		$lib->needClass('yamlfilenode');
		$this->node=&new yamlFileNode($this->cfg['file']);
		//$this->node->load();
		//$this->data=$this->node->getData();
		//echo wakdebug::vardump($this->data);
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* returns one question at random
	* @param
	* @access public
	* @return string question
	*/
	function randomQuestion() {
		if (!$this->data)
			$this->data=$this->node->getdata();
		return array_rand($this->data);
	}/**/
	
	/**
	* checks answer for a question
	* @param string $question
	* @param string $answer
	* @access public
	* @return bool
	*/
	function checkAnswer($question,$answer) {
		$answer=trim($answer);
		if (!$this->data)
			$this->data=$this->node->getdata();
		/*echo wakdebug::vardump($this->data[$question])
			.wakdebug::vardump($this->data[$question])
			.'=='.wakdebug::vardump($answer);*/
		return strtolower($this->data[$question])==strtolower($answer);
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var array configuration data
	*/
	var $cfg=array(
		'file'=>'data.store/turingquestions.yml'
	);
	/**
	* @var yamlFileNode questions storage
	*/
	var $node;
	/**
	* @var array questions cache
	*/
	var $data;
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
